﻿//==============================================================================  
//Copyright (C) 2012-2015 9UN.ORG. All rights reserved. 
//GUID：5e744086-74e4-4068-a089-6479949f5d45
//CLR Version: 4.0.30319.18033
//Code Author：Kevin Wang
//Contact：Email(Admin@9un.org),QQ(265382 or 74344)
//Filename：LibVlcAudioInterop
//Namespace：RuanRang.Media.Core.Internal.Interop
//Functions：LibVlcAudioInterop  
//Created by Kevin Wang at 2013/3/3 15:17:26 http://blog.9un.org
//============================================================================== 
using System;
using System.Runtime.InteropServices;
using System.Security;
using RuanRang.Media.Core.Internal.DataStructures;
using log4net;

namespace RuanRang.Media.Core.Internal.Interop
{
    internal class LibVlcAudioInterop : BaseInterop
    {
        /// <summary>
        /// Initializes static members of the <see cref="LibVlcAudioInterop"/> class.
        /// </summary>
        static LibVlcAudioInterop()
        {
            Logger = LogManager.GetLogger(typeof(LibVlcAudioInterop));
        }

        #region Volume

        /// <summary>
        /// Libvlc_audio_get_volume_unmanageds the specified libvlc_media_player_t.
        /// </summary>
        /// <param name="libvlc_media_player_t">The libvlc_media_player_t.</param>
        /// <returns>System.Int32.</returns>
        [DllImport("libvlc", ExactSpelling = true, EntryPoint = "libvlc_audio_get_volume")]
        [SuppressUnmanagedCodeSecurity]
        private static extern int libvlc_audio_get_volume_unmanaged(IntPtr libvlc_media_player_t);

        /// <summary>
        /// Libvlc_audio_get_volumes the specified libvlc_media_player_t.
        /// </summary>
        /// <param name="libvlc_media_player_t">The libvlc_media_player_t.</param>
        /// <returns>System.Int32.</returns>
        public static int libvlc_audio_get_volume(IntPtr libvlc_media_player_t)
        {
            if (CallTraceEnabled)
            {
                TraceCall("libvlc_audio_get_volume");
            }
            return libvlc_audio_get_volume_unmanaged(libvlc_media_player_t);
        }

        /// <summary>
        /// Libvlc_audio_set_volume_unmanageds the specified libvlc_media_player_t.
        /// </summary>
        /// <param name="libvlc_media_player_t">The libvlc_media_player_t.</param>
        /// <param name="volume">The volume.</param>
        /// <returns>Int32.</returns>
        [DllImport("libvlc", ExactSpelling = true, EntryPoint = "libvlc_audio_set_volume")]
        [SuppressUnmanagedCodeSecurity]
        private static extern Int32 libvlc_audio_set_volume_unmanaged(IntPtr libvlc_media_player_t, Int32 volume);

        /// <summary>
        /// Libvlc_audio_set_volumes the specified libvlc_media_player_t.
        /// </summary>
        /// <param name="libvlc_media_player_t">The libvlc_media_player_t.</param>
        /// <param name="volume">The volume.</param>
        /// <returns>Int32.</returns>
        public static Int32 libvlc_audio_set_volume(IntPtr libvlc_media_player_t, Int32 volume)
        {
            if (CallTraceEnabled)
            {
                TraceCall("libvlc_audio_set_volume");
            }
            return libvlc_audio_set_volume_unmanaged(libvlc_media_player_t, volume);
        }

        #endregion

        /// <summary>
        /// Get the list of available audio outputs.
        /// </summary>
        /// <param name="instance">Libvlc instance</param>
        /// <returns>List of available audio outputs. It must be freed it with. In case of error, NULL is returned.</returns>
        [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)]
        [SuppressUnmanagedCodeSecurity]
        public static extern libvlc_audio_output_t libvlc_audio_output_list_get(IntPtr instance);

        /// <summary> 
        /// Libvlc_audio_output_list_get_s the int PTR.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <returns></returns>
        [DllImport("libvlc", ExactSpelling = true, EntryPoint = "libvlc_audio_output_list_get")]
        [SuppressUnmanagedCodeSecurity]
        public static extern IntPtr libvlc_audio_output_list_get_IntPtr(IntPtr instance);

        /// <summary>
        /// Free the list of available audio outputs.
        /// </summary>
        /// <param name="list">List with audio outputs for release</param>
        [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)]
        [SuppressUnmanagedCodeSecurity]
        public static extern void libvlc_audio_output_list_release(libvlc_audio_output_t list);

        /// <summary>
        /// Libvlc_audio_output_list_releases the specified list.
        /// </summary>
        /// <param name="list">The list.</param>
        [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)]
        [SuppressUnmanagedCodeSecurity]
        public static extern void libvlc_audio_output_list_release(IntPtr list);

        /// <summary>
        /// Set the audio output.
        /// Change will be applied after stop and play.
        /// </summary>
        /// <param name="player">Media player instance</param>
        /// <param name="name">Name of audio output (use psz_name of <see cref="libvlc_audio_output_t"/>)</param>
        /// <returns>True if function succeded</returns>
        [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)]
        [SuppressUnmanagedCodeSecurity]
        public static extern int libvlc_audio_output_set(IntPtr playerInstance, string name);

        /// <summary>
        /// Get count of devices for audio output, these devices are hardware oriented like analor or digital output of sound card.
        /// </summary>
        /// <param name="instance">Libvlc instance</param>
        /// <param name="audioOutput">Name of audio output, <see cref="libvlc_audio_output_t"/></param>
        /// <returns>Number of devices</returns>
        [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)]
        [SuppressUnmanagedCodeSecurity]
        public static extern int libvlc_audio_output_device_count(IntPtr instance, string audioOutput);

        /// <summary>
        /// Get long name of device, if not available short name given.
        /// </summary>
        /// <param name="instance">Libvlc instance</param>
        /// <param name="audioOutput">Name of audio output, <see cref="libvlc_audio_output_t"/></param>
        /// <param name="deviceId">Device index</param>
        /// <returns>Long name of device</returns>
        [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)]
        [SuppressUnmanagedCodeSecurity]
        public static extern IntPtr libvlc_audio_output_device_longname(IntPtr instance, string audioOutput, int deviceId);

        /// <summary>
        /// Get id name of device
        /// </summary>
        /// <param name="instance">Libvlc instance</param>
        /// <param name="audioOutput">Name of audio output, <see cref="libvlc_audio_output_t"/></param>
        /// <param name="deviceId">Device index</param>
        /// <returns>Id name of device, use for setting device, need to be free after use</returns>
        [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)]
        [SuppressUnmanagedCodeSecurity]
        public static extern IntPtr libvlc_audio_output_device_id(IntPtr instance, string audioOutput, int deviceId);

        /// <summary>
        /// Set audio output device. Changes are only effective after stop and play.
        /// </summary>
        /// <param name="playerInstance">Media Player instance</param>
        /// <param name="audioOutput">Name of audio output, <see cref="libvlc_audio_output_t"/></param>
        /// <param name="deviceId">Device index</param>
        [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)]
        [SuppressUnmanagedCodeSecurity]
        public static extern void libvlc_audio_output_device_set(IntPtr playerInstance, string audioOutput, string deviceId);

        /// <summary>
        /// Get current audio device type. Device type describes something like character of output sound - stereo sound, 2.1, 5.1 etc
        /// </summary>
        /// <param name="playerInstance">Media Player instance</param>
        /// <returns>Audio devices type <see cref="libvlc_audio_output_device_types_t"/></returns>
        [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)]
        [SuppressUnmanagedCodeSecurity]
        public static extern int libvlc_audio_output_get_device_type(IntPtr playerInstance);

        /// <summary>
        /// Set current audio device type.
        /// </summary>
        /// <param name="playerInstance">Media Player instance</param>
        /// <param name="deviceType">Audio device type</param>
        [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)]
        [SuppressUnmanagedCodeSecurity]
        public static extern void libvlc_audio_output_set_device_type(IntPtr playerInstance, libvlc_audio_output_device_type_t deviceType);

        /// <summary>
        /// Libvlc_audio_output_set_device_types the specified player instance.
        /// </summary>
        /// <param name="playerInstance">The player instance.</param>
        /// <param name="deviceType">Type of the device.</param>
        [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)]
        [SuppressUnmanagedCodeSecurity]
        public static extern void libvlc_audio_output_set_device_type(IntPtr playerInstance, uint deviceType);

        /// <summary>
        /// Toggle mute status.
        /// </summary>
        /// <param name="playerInstance">Media Player instance</param>
        [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)]
        [SuppressUnmanagedCodeSecurity]
        public static extern void libvlc_audio_toggle_mute(IntPtr playerInstance);

        /// <summary>
        /// Get current mute status.
        /// </summary>
        /// <param name="playerInstance">Media Player instance</param>
        /// <returns>Mute status</returns>
        [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)]
        [SuppressUnmanagedCodeSecurity]
        public static extern int libvlc_audio_get_mute(IntPtr playerInstance);

        /// <summary>
        /// Set mute status.
        /// </summary>
        /// <param name="playerInstance">Media Player instance</param>
        /// <param name="status">If status is true then mute, otherwise unmute</param>
        [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)]
        [SuppressUnmanagedCodeSecurity]
        public static extern void libvlc_audio_set_mute(IntPtr playerInstance, int status);

        /// <summary>
        /// Get number of available audio tracks.
        /// </summary>
        /// <param name="playerInstance">Media Player instance</param>
        /// <returns>Number of available audio tracks, or -1 if unavailable</returns>
        [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)]
        [SuppressUnmanagedCodeSecurity]
        public static extern int libvlc_audio_get_track_count(IntPtr playerInstance);

        /// <summary>
        /// Get the description of available audio tracks.
        /// </summary>
        /// <param name="playerInstance">Media Player instance</param>
        /// <returns>Description of available audio tracks, or NULL</returns>
        [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)]
        [SuppressUnmanagedCodeSecurity]
        public static extern libvlc_track_description_t libvlc_audio_get_track_description(IntPtr playerInstance);

        /// <summary>
        /// Get current audio track.
        /// </summary>
        /// <param name="playerInstance">Media Player instance</param>
        /// <returns>Audio track, or -1 if none</returns>
        [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)]
        [SuppressUnmanagedCodeSecurity]
        public static extern int libvlc_audio_get_track(IntPtr playerInstance);

        /// <summary>
        /// Set current audio track.
        /// </summary>
        /// <param name="playerInstance">Media Player instance</param>
        /// <param name="track">Track</param>
        /// <returns>0 on success, -1 on error</returns>
        [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)]
        [SuppressUnmanagedCodeSecurity]
        public static extern int libvlc_audio_set_track(IntPtr playerInstance, int track);

        /// <summary>
        /// Get current audio channel.
        /// </summary>
        /// <param name="playerInstance">Media Player instance</param>
        /// <returns>audio channel <see cref="libvlc_audio_output_channel_t"/></returns>
        [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)]
        [SuppressUnmanagedCodeSecurity]
        public static extern int libvlc_audio_get_channel(IntPtr playerInstance);

        /// <summary>
        /// Set current audio channel.
        /// </summary>
        /// <param name="playerInstance">Media Player instance</param>
        /// <param name="channel">audio channel, <see cref="libvlc_audio_output_channel_t"/></param>
        /// <returns>0 on success, -1 on error</returns>
        [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)]
        [SuppressUnmanagedCodeSecurity]
        public static extern int libvlc_audio_set_channel(IntPtr playerInstance, int channel);

        /// <summary>
        /// Get current audio delay.
        /// </summary>
        /// <param name="playerInstance">Media Player instance</param>
        /// <returns>Audio delay (microseconds)</returns>
        [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)]
        [SuppressUnmanagedCodeSecurity]
        public static extern Int64 libvlc_audio_get_delay(IntPtr playerInstance);

        /// <summary>
        /// Set current audio delay. The audio delay will be reset to zero each time the media changes.
        /// </summary>
        /// <param name="playerInstance">Media Player instance</param>
        /// <param name="delay">Audio delay (microseconds)</param>
        /// <returns>0 on success, -1 on error</returns>
        [DllImport("libvlc", CallingConvention = CallingConvention.Cdecl)]
        [SuppressUnmanagedCodeSecurity]
        public static extern int libvlc_audio_set_delay(IntPtr playerInstance, Int64 delay);
    }
}
